<?php
namespace app\cms\upgrade;

use think\Db;

class U2{
	public static function up(){
	    
	    if (!table_field('cms_field','input_width')) {
	        query("ALTER TABLE  `qb_cms_field` ADD  `input_width` VARCHAR( 7 ) NOT NULL COMMENT  '输入表单宽度',ADD  `input_height` VARCHAR( 7 ) NOT NULL COMMENT  '输入表单高度',ADD  `unit` VARCHAR( 20 ) NOT NULL COMMENT  '单位名称',ADD  `match` VARCHAR( 150 ) NOT NULL COMMENT  '表单正则匹配',ADD  `css` VARCHAR( 20 ) NOT NULL COMMENT  '表单CSS类名';");
	    }
	    if (!table_field('cms_field','script')) {
	        query("ALTER TABLE  `qb_cms_field` ADD  `script` TEXT NOT NULL COMMENT  'JS脚本',ADD  `trigger` VARCHAR( 255 ) NOT NULL COMMENT  '选择某一项后,联动触发显示其它字段';");
	    }
	    if ( !table_field('cms_field','range_opt') ) {
	        query("ALTER TABLE  `qb_cms_field` ADD  `range_opt` TEXT NOT NULL COMMENT  '范围选择,比如价格范围',ADD  `group_view` VARCHAR( 255 ) NOT NULL COMMENT  '允许哪些用户组查看',ADD  `index_hide` TINYINT( 1 ) NOT NULL COMMENT  '是否前台不显示并不做转义处理';");
	    }
	    
	    $id = 0;
	    $result = Db::name('cms_module')->where('keyword','voice')->find();
	    
	    if (empty($result)) {
	        $data = [
	            'keyword'=>'voice',
	            'title'=>'音频模型',
	            'create_time'=>time(),
	        ];
	        $id = Db::name('cms_module')->insertGetId($data);
	    }
	    
	    if($id>0){
	        into_sql("
CREATE TABLE IF NOT EXISTS `qb_cms_content{$id}` (
  `id` int(8) unsigned NOT NULL AUTO_INCREMENT,
  `mid` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT '模型ID',
  `fid` mediumint(7) unsigned NOT NULL DEFAULT '0' COMMENT '栏目ID',
  `title` varchar(256) NOT NULL DEFAULT '' COMMENT '标题',
  `ispic` tinyint(2) NOT NULL DEFAULT '0' COMMENT '是否带组图',
  `picurl` text NOT NULL COMMENT '封面图',
  `uid` int(8) unsigned NOT NULL DEFAULT '0' COMMENT '用户ID',
  `view` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT '浏览量',
  `status` tinyint(2) NOT NULL DEFAULT '1' COMMENT '状态：0未审 1已审 2推荐',
  `agree` mediumint(5) NOT NULL DEFAULT '0' COMMENT '点赞',
  `replynum` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT '评论数',
  `content` text NOT NULL COMMENT '内容介绍',
  `create_time` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '创建时间',
  `update_time` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '修改时间',
  `list` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '排序值',
  `voice_url` varchar(128) NOT NULL COMMENT '音频地址',
  `province_id` mediumint(5) NOT NULL COMMENT '省会ID',
  `city_id` mediumint(5) NOT NULL COMMENT '城市ID',
  `zone_id` mediumint(5) NOT NULL COMMENT '县级市或所在区ID',
  `street_id` mediumint(5) NOT NULL COMMENT '乡镇或区域街道ID',
  `ext_sys` mediumint(5) NOT NULL COMMENT '扩展字段,关联的系统',
  `ext_id` int(8) NOT NULL COMMENT '扩展字段,供其它调用',
  `keywords` varchar(128) NOT NULL COMMENT 'SEO关键字',
  `price` decimal(10,2) NOT NULL COMMENT '收费阅读',
  `description` varchar(255) NOT NULL COMMENT '简介(SEO描述)',
  PRIMARY KEY (`id`),
  KEY `mid` (`mid`),
  KEY `fid` (`fid`),
  KEY `view` (`view`),
  KEY `status` (`status`),
  KEY `list` (`list`),
  KEY `ispic` (`ispic`),
  KEY `province_id` (`province_id`),
  KEY `city_id` (`city_id`),
  KEY `ext_id` (`ext_id`,`ext_sys`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COMMENT='音频模型内容主表' AUTO_INCREMENT=1 ;



INSERT INTO `qb_cms_field` (`id`, `name`, `title`, `type`, `field_type`, `value`, `options`, `about`, `show`, `mid`, `ajax_url`, `next_items`, `param`, `format`, `table`, `level`, `key`, `option`, `pid`, `list`, `listshow`, `ifsearch`, `ifmust`, `nav`, `input_width`, `input_height`, `unit`, `match`, `css`, `script`, `trigger`, `range_opt`, `group_view`, `index_hide`) VALUES(0, 'title', '标题', 'text', 'varchar(256) NOT NULL', NULL, NULL, '', 0, {$id}, '', '', '', '', '', 2, '', '', '', 100, 1, 1, 1, '', '', '', '', '', '', '', '', '', '', 0);
INSERT INTO `qb_cms_field` (`id`, `name`, `title`, `type`, `field_type`, `value`, `options`, `about`, `show`, `mid`, `ajax_url`, `next_items`, `param`, `format`, `table`, `level`, `key`, `option`, `pid`, `list`, `listshow`, `ifsearch`, `ifmust`, `nav`, `input_width`, `input_height`, `unit`, `match`, `css`, `script`, `trigger`, `range_opt`, `group_view`, `index_hide`) VALUES(0, 'picurl', '封面图', 'image', 'varchar(128) NOT NULL', '', '', '', 0, {$id}, '', '', '', '', '', 2, '', '', '', 90, 0, 0, 0, '', '', '', '', '', '', '', '', '', '', 0);
INSERT INTO `qb_cms_field` (`id`, `name`, `title`, `type`, `field_type`, `value`, `options`, `about`, `show`, `mid`, `ajax_url`, `next_items`, `param`, `format`, `table`, `level`, `key`, `option`, `pid`, `list`, `listshow`, `ifsearch`, `ifmust`, `nav`, `input_width`, `input_height`, `unit`, `match`, `css`, `script`, `trigger`, `range_opt`, `group_view`, `index_hide`) VALUES(0, 'content', '内容介绍', 'ueditor', 'text NOT NULL', '', '', '', 0, {$id}, '', '', '', '', '', 2, '', '', '', -1, 0, 0, 0, '', '', '', '', '', '', '', '', '', '', 0);
INSERT INTO `qb_cms_field` (`id`, `name`, `title`, `type`, `field_type`, `value`, `options`, `about`, `show`, `mid`, `ajax_url`, `next_items`, `param`, `format`, `table`, `level`, `key`, `option`, `pid`, `list`, `listshow`, `ifsearch`, `ifmust`, `nav`, `input_width`, `input_height`, `unit`, `match`, `css`, `script`, `trigger`, `range_opt`, `group_view`, `index_hide`) VALUES(0, 'voice_url', '音频地址', 'file', 'varchar(128) NOT NULL', '', '', '', 0, {$id}, '', '', '', '', '', 2, '', '', '', 80, 0, 0, 1, '', '', '', '', '', '', '', '', '', '', 1);
INSERT INTO `qb_cms_field` (`id`, `name`, `title`, `type`, `field_type`, `value`, `options`, `about`, `show`, `mid`, `ajax_url`, `next_items`, `param`, `format`, `table`, `level`, `key`, `option`, `pid`, `list`, `listshow`, `ifsearch`, `ifmust`, `nav`, `input_width`, `input_height`, `unit`, `match`, `css`, `script`, `trigger`, `range_opt`, `group_view`, `index_hide`) VALUES(0, 'keywords', 'SEO关键字', 'text', 'varchar(128) NOT NULL', '', '', '', 1, {$id}, '', '', '', '', '', 2, '', '', '', 98, 0, 0, 0, '', '', '', '', '', '', '', '', '', '', 1);
INSERT INTO `qb_cms_field` (`id`, `name`, `title`, `type`, `field_type`, `value`, `options`, `about`, `show`, `mid`, `ajax_url`, `next_items`, `param`, `format`, `table`, `level`, `key`, `option`, `pid`, `list`, `listshow`, `ifsearch`, `ifmust`, `nav`, `input_width`, `input_height`, `unit`, `match`, `css`, `script`, `trigger`, `range_opt`, `group_view`, `index_hide`) VALUES(0, 'price', '付费阅读(元)', 'money', 'decimal(10,2) unsigned NOT NULL', '', '', '', 1, {$id}, '', '', '', '', '', 0, '', '', '', 0, 0, 0, 0, '', '', '', '', '', '', '', '', '', '', 1);
INSERT INTO `qb_cms_field` (`id`, `name`, `title`, `type`, `field_type`, `value`, `options`, `about`, `show`, `mid`, `ajax_url`, `next_items`, `param`, `format`, `table`, `level`, `key`, `option`, `pid`, `list`, `listshow`, `ifsearch`, `ifmust`, `nav`, `input_width`, `input_height`, `unit`, `match`, `css`, `script`, `trigger`, `range_opt`, `group_view`, `index_hide`) VALUES(0, 'description', '简介(SEO描述)', 'textarea', 'varchar(255) NOT NULL', '', '', '', 1, {$id}, '', '', '', '', '', 2, '', '', '', 0, 0, 0, 0, '', '', '', '', '', '', '', '', '', '', 1);


INSERT INTO `qb_cms_field` (`id`, `name`, `title`, `type`, `field_type`, `value`, `options`, `about`, `show`, `mid`, `ajax_url`, `next_items`, `param`, `format`, `table`, `level`, `key`, `option`, `pid`, `list`, `listshow`, `ifsearch`, `ifmust`, `nav`) VALUES(0, 'fx1', '直接推荐人收益', 'money', 'decimal(5,2) unsigned NOT NULL', '', '', '注意:0.01代表1%的分成，并不是0.01元，以此类推', 1, {$id}, '', '', '', '', '', 2, '', '', '', 0, 0, 0, 0, '分销设置');
INSERT INTO `qb_cms_field` (`id`, `name`, `title`, `type`, `field_type`, `value`, `options`, `about`, `show`, `mid`, `ajax_url`, `next_items`, `param`, `format`, `table`, `level`, `key`, `option`, `pid`, `list`, `listshow`, `ifsearch`, `ifmust`, `nav`) VALUES(0, 'fx2', '间接推荐人收益', 'money', 'decimal(5,2) unsigned NOT NULL', '', '', '注意:0.01代表1%的分成，并不是0.01元，以此类推', 1, {$id}, '', '', '', '', '', 2, '', '', '', 0, 0, 0, 0, '分销设置');
INSERT INTO `qb_cms_field` (`id`, `name`, `title`, `type`, `field_type`, `value`, `options`, `about`, `show`, `mid`, `ajax_url`, `next_items`, `param`, `format`, `table`, `level`, `key`, `option`, `pid`, `list`, `listshow`, `ifsearch`, `ifmust`, `nav`) VALUES(0, 'fx3', '三级推荐人收益', 'money', 'decimal(5,2) unsigned NOT NULL', '', '', '注意:0.01代表1%的分成，并不是0.01元，以此类推', 1, {$id}, '', '', '', '', '', 2, '', '', '', 0, 0, 0, 0, '分销设置');

ALTER TABLE  `qb_cms_content{$id}` ADD  `fx1` DECIMAL( 5, 2 ) NOT NULL COMMENT  '直接推荐人收益';
ALTER TABLE  `qb_cms_content{$id}` ADD  `fx2` DECIMAL( 5, 2 ) NOT NULL COMMENT  '间接推荐人收益';
ALTER TABLE  `qb_cms_content{$id}` ADD  `fx3` DECIMAL( 5, 2 ) NOT NULL COMMENT  '三级推荐人收益';


UPDATE  `qb_cms_field` SET  `index_hide` =  '1' WHERE  `name` = 'fx1';
UPDATE  `qb_cms_field` SET  `index_hide` =  '1' WHERE  `name` = 'fx2';
UPDATE  `qb_cms_field` SET  `index_hide` =  '1' WHERE  `name` = 'fx3';

ALTER TABLE  `qb_cms_content4` CHANGE  `voice_url`  `voice_url` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT  '音频地址';
UPDATE `qb_cms_field` SET  `type` =  'files2',`field_type` =  'text NOT NULL'  WHERE `name` = 'voice_url';

INSERT INTO `qb_cms_field` (`id`, `name`, `title`, `type`, `field_type`, `value`, `options`, `about`, `show`, `mid`, `ajax_url`, `next_items`, `param`, `format`, `table`, `level`, `key`, `option`, `pid`, `list`, `listshow`, `ifsearch`, `ifmust`, `nav`, `input_width`, `input_height`, `unit`, `match`, `css`, `script`, `trigger`, `range_opt`, `group_view`, `index_hide`) VALUES(0, 'myfid', '我的分类', 'select', 'int(7) NOT NULL DEFAULT ''0''', '', 'cms_mysort@id,name@uid', '<script>if($(\"#atc_myfid\").children().length<1)$(\"#form_group_myfid\").hide();</script>', 1, 4, '', '', '', '', '', 2, '', '', '', 0, 0, 0, 0, '', '', '', '', '', '', '', '', '', '', 0);
ALTER TABLE  `qb_cms_content4` ADD  `myfid` INT( 7 ) NOT NULL COMMENT  '我的分类';

");
	    }
		  
	}
}


